/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServerUI.java
 *
 * Created on Nov 29, 2011, 10:22:45 AM
 */

package CP2013Server;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

/**
 *
 * @author AcerXPS
 */
public class ServerUI extends javax.swing.JFrame {

        private AuctionServer server = new AuctionServer();
        private Thread serverThread = new Thread(server);
    /** Creates new form ServerUI */
    public ServerUI() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlServer = new javax.swing.JPanel();
        lblServer = new javax.swing.JLabel();
        btnStart = new javax.swing.JButton();
        btnObject = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Auction Server");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        lblServer.setFont(new java.awt.Font("Copperplate Gothic Light", 1, 18));
        lblServer.setText("Auction Server");

        btnStart.setText("Start Server");
        btnStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartActionPerformed(evt);
            }
        });

        btnObject.setText("Manage Auction Objects");
        btnObject.setEnabled(false);
        btnObject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnObjectActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlServerLayout = new javax.swing.GroupLayout(pnlServer);
        pnlServer.setLayout(pnlServerLayout);
        pnlServerLayout.setHorizontalGroup(
            pnlServerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlServerLayout.createSequentialGroup()
                .addGroup(pnlServerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlServerLayout.createSequentialGroup()
                        .addGap(120, 120, 120)
                        .addComponent(lblServer))
                    .addGroup(pnlServerLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnlServerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnStart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnObject, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE))))
                .addContainerGap(107, Short.MAX_VALUE))
        );
        pnlServerLayout.setVerticalGroup(
            pnlServerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlServerLayout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addComponent(lblServer)
                .addGap(18, 18, 18)
                .addComponent(btnStart)
                .addGap(18, 18, 18)
                .addComponent(btnObject)
                .addContainerGap(98, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlServer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlServer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
        serverThread.start();
        btnStart.setEnabled(false);
        btnObject.setEnabled(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnStartActionPerformed

    private void btnObjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnObjectActionPerformed
        server.manageO();       // TODO add your handling code here:
    }//GEN-LAST:event_btnObjectActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        int optionChoice = JOptionPane.showConfirmDialog(rootPane, "Are you sure to exit?", "Exit program?", JOptionPane.YES_NO_OPTION);
        if(optionChoice == JOptionPane.YES_OPTION){
            System.exit(1);
        }else{
            
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnObject;
    private javax.swing.JButton btnStart;
    private javax.swing.JLabel lblServer;
    private javax.swing.JPanel pnlServer;
    // End of variables declaration//GEN-END:variables

}
